class Solution {
    public int numDistinct(String s, String t) {
        int m = t.length();
        int n = s.length();
        int[][] dp = new int[m + 1][n + 1];// t 的 [0, i] 区间在 s 的 [0, j] 区间上出现的次数
        for(int j = 0; j < n; j++) dp[0][j] = 1;
        String s1 = " " + t;
        String s2 = " " + s;
        for(int i = 1; i <= m; i++){
            for(int j = 1; j <= n; j++){
                if(s1.charAt(i) == s2.charAt(j)) dp[i][j] += dp[i - 1][j - 1];
                dp[i][j] += dp[i][j - 1];
            }
        }
        return dp[m][n];
    }
}